<?php
namespace app\common\model\member;
use app\common\model\setting\SettingStorePlatformModel;
use think\Model;

class MemberAccountModel extends Model
{
    // 表名
    protected $name = 'member_account';
    // 表主键
    protected $pk = 'id';
    const LEVEL = [
        ['value' => 1, 'label' => '1心','code' => 'one'],
        ['value' => 2, 'label' => '2心','code' => 'two'],
        ['value' => 3, 'label' => '3心','code' => 'three'],
        ['value' => 4, 'label' => '4心','code' => 'four'],
        ['value' => 5, 'label' => '5心','code' => 'five'],
        ['value' => 6, 'label' => '1钻','code' => 'six'],
        ['value' => 7, 'label' => '2钻','code' => 'seven'],
        ['value' => 8, 'label' => '3钻','code' => 'eight'],
        ['value' => 9, 'label' => '4钻','code' => 'nine'],
        ['value' => 10, 'label' => '5钻','code' => 'ten'],
        ['value' => 11, 'label' => '1冠','code' => 'eleven'],
        ['value' => 12, 'label' => '2冠','code' => 'twelve'],
        ['value' => 13, 'label' => '3冠','code' => 'thirteen'],
        ['value' => 14, 'label' => '4冠','code' => 'fourteen'],
        ['value' => 15, 'label' => '5冠','code' => 'fifteen'],
    ];

    /**
     * 查询等级
     * @Author: 易军辉
     * @DateTime:2024-06-18 16:10
     * @param $key 编码或value
     * @param $type 1、查询value  2、查询名称 3、查询编码
     * @return mixed|void
     */
    public static  function getLevel($key,$type=1)
    {
        foreach (self::LEVEL as $status) {
            if ($status['code'] == $key || $status['value'] == $key) {
                switch ($type) {
                    case 1:
                        return $status['value']; // 返回value
                    case 2:
                        return $status['label']; // 返回名称
                    default:
                        return $status['code']; // 未知类型，返回null
                }
            }
        }
    }
    // 关联买手
    public function member()
    {
        return $this->hasOne(MemberModel::class, 'member_id', 'member_id');
    }
    // 关联平台
    public function platform()
    {
        return $this->hasOne(SettingStorePlatformModel::class, 'id', 'store_platform_id');
    }
}
